using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace UselessExplorer
{
    public partial class frmTxtViewer : Form
    {
        public frmTxtViewer()
        {
            InitializeComponent();
        }
        private string path;

        public string Path
        {
            get { return path; }
            set { path = value; }
        }

        public frmTxtViewer(string filePath)
        {
            InitializeComponent();

            Path = filePath;
            
        }

        private void frmTxtViewer_Load(object sender, EventArgs e)
        {
            this.Text = UselessExplorer.Properties.UselessResources.frmTxtViewerTitle;
            clsGlobal cg = new clsGlobal();
            this.Left = cg.FormLeft;
            this.Top = cg.FormTop;
            try
            {
                FileInfo fi = new FileInfo(Path);
                this.Text = fi.Name;
                if (fi.Extension.ToUpper() == ".JPG" || fi.Extension.ToUpper() == ".GIF" || fi.Extension.ToUpper() == ".JPEG" || fi.Extension.ToUpper() == ".BMP" || fi.Extension.ToUpper() == ".TIF" || fi.Extension.ToUpper() == ".PNG")
                {
                    this.richTextBox1.Visible = false;
                    this.pictureBox1.Load(Path);

                    Image im = Image.FromFile(Path);
                    this.pictureBox1.Height = im.Height;
                    this.pictureBox1.Width = im.Width;
                    this.pictureBox1.BackColor = Color.Transparent;

                    this.Height = im.Height + 70;
                    this.Width = im.Width + 50;

                    if (this.Width < 100)
                        this.Width = 120;
                }
                else
                {
                    this.pictureBox1.Visible = false;
                    if (File.Exists(Path))
                    {
                        StreamReader SR;
                        string S;
                        SR = File.OpenText(Path);
                        S = SR.ReadToEnd();

                        richTextBox1.Text = S;

                        SR.Close();
                    }
                    else
                    {
                        throw new Exception("File Does Not Exist");
                    }
                }
            }
            catch (Exception ex)
            {
                cg.WriteLogs(Logger.LogsCategory.Exception, ex);
            }
        }

        private void filePropertiesToolStripMenuItem_Click(object sender, EventArgs e)
        {
            frmProperties fp = new frmProperties(Path, false);
            fp.ShowDialog();
        }

        private void menuStrip1_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
        {

        }
    }
}